package com.sc.nft.entity.vo;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sc.nft.enums.ApplicationRequirementEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Data
public class NewPerformanceVO {

    @ApiModelProperty("团队持仓藏品总额")
    private String teamCollectionIsHoldSum = "0";

    @ApiModelProperty("团队生态熔炼值总额")
    private String teamEcologicalSmeltingSum = "0";

    @ApiModelProperty("直属账户")
    private Integer immediateAccount = 0;

    @ApiModelProperty("团队账户")
    private Integer teamAccount = 0;

    @ApiModelProperty("团队社区网点")
    private Integer teamCommunityNetwork = 0;

    @ApiModelProperty("团队城市服务中心")
    private Integer teamCityServiceCenter = 0;

    @JsonIgnore
    private List<ApplicationRequirementFactoryVO> resultList;


    public void setResultList(List<ApplicationRequirementFactoryVO> resultList) {
        this.resultList = resultList;
        // 根据里面的内容,把数据匹配进去对应的字段里面
        Map<ApplicationRequirementEnum, List<ApplicationRequirementFactoryVO>> collect = resultList.stream().collect(Collectors.groupingBy(ApplicationRequirementFactoryVO::getApplicationRequirementEnum));
        collect.forEach((applicationRequirementEnum, applicationRequirementFactoryVOS) -> {
            // 直属账户
            if (applicationRequirementEnum.equals(ApplicationRequirementEnum.IMMEDIATE_ACCOUNT)) {
                if (CollUtil.isNotEmpty(applicationRequirementFactoryVOS)) {
                    this.immediateAccount = applicationRequirementFactoryVOS.get(0).getPracticalValue();
                }
            }
            // 团队账户
            if (applicationRequirementEnum.equals(ApplicationRequirementEnum.TEAM_ACCOUNT)) {
                if (CollUtil.isNotEmpty(applicationRequirementFactoryVOS)) {
                    this.teamAccount = applicationRequirementFactoryVOS.get(0).getPracticalValue();
                }
            }
            // 团队藏品持仓金额
            if (applicationRequirementEnum.equals(ApplicationRequirementEnum.TOTAL_HOLDINGS_OF_TEAM_COLLECTIONS)) {
                if (CollUtil.isNotEmpty(applicationRequirementFactoryVOS)) {
                    this.teamCollectionIsHoldSum ="¥"+ Convert.toBigDecimal(applicationRequirementFactoryVOS.get(0).getPracticalValue()).setScale(2,BigDecimal.ROUND_DOWN).stripTrailingZeros().toPlainString();
                }
            }
            // 团队生态熔炼总额
            if (applicationRequirementEnum.equals(ApplicationRequirementEnum.TOTAL_TEAM_ECO_MELTING_VALUE)) {
                if (CollUtil.isNotEmpty(applicationRequirementFactoryVOS)) {
                    this.teamEcologicalSmeltingSum ="¥"+ Convert.toBigDecimal(applicationRequirementFactoryVOS.get(0).getPracticalValue()).setScale(2,BigDecimal.ROUND_DOWN).stripTrailingZeros().toPlainString();
                }
            }
        });
    }
}
